home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Taifun / Taifun 014 (1987-05-15)(Ossowski, Stefan)(DE)(PD).zip / Taifun 014 (1987-05-15)(Ossowski, Stefan)(DE)(PD).adf / Cos / xBMAPS / newconvertfd.bas < prev   
BASIC Source File  |  1987-03-04  |  5KB  |  184 lines

  1. 'NewConvertFD
  2. ' from ConvertFd - created Aug 9, 1985
  3. 'This program converts .fd files, like 'graphics_lib.fd' to
  4. ' .bmap format files, like 'graphics.bmap', so BASIC
  5. ' programs can access libraries of machine language routines
  6. ' by name via the LIBRARY statement.
  7. '
  8. ' Modified  01/86 by Carolyn Scheppner  CBM
  9. '   Prepends an x to all function names which
  10. '    conflict with AmigaBasic keywords.
  11. '    See data statements at end of program for
  12. '    known conflicts.  To call these functions,
  13. '    prepend an x  (example  xRead).
  14. '   Saves the .bmap file in current or specified
  15. '    directory (previously saved in LIBS:).
  16. '    For your program to access the .bmap via
  17. '    LIBRARY, it must be in the current dir
  18. '    or the LIBS: dir.
  19. '   As far as I know, you MUST name your .bmap
  20. '    libraryname.bmap.  The libraryname is the
  21. '    part of the .fd file name before the _.
  22. '    (example   dos.bmap from dos_lib.fd)
  23.  
  24.   DEFINT a-Z    'by default, all variables are integer
  25.  
  26.   REM ******** for conflicting tokens ********
  27.   READ cnt       'count of conflicting tokens
  28.   DIM con$(cnt)
  29.   FOR k = 0 TO cnt-1: READ con$(k): NEXT
  30.   REM ****************************************
  31.  
  32.   INPUT "Enter name of .fd file to read > ",fdFilename$
  33.   OPEN fdFilename$ FOR INPUT AS #1
  34.   INPUT "Enter name of .bmap file to produce > ",bmapFilename$
  35.   OPEN bmapFilename$ FOR OUTPUT AS #2
  36.   WHILE NOT EOF(1)
  37.     GetLine
  38.     IF char$ = "#" THEN
  39.       'lines which begin with "#" are command lines
  40.       GOSUB GotCommand
  41.     ELSEIF char$ = "*" THEN
  42.       'lines which begin with "*" are comment lines
  43.     ELSE
  44.       'all other lines define a function in the library
  45.       GOSUB GotFunction
  46.     END IF
  47.   WEND
  48.   CLOSE
  49.   END
  50.  
  51. GotCommand:
  52.   GetChar  'skip 1st "#"
  53.   GetChar  'skip 2nd "#"
  54.   GetToken
  55.   IF token$ = "bias" THEN
  56.     GetNum
  57.     offset = -num
  58.   END IF
  59.  ram: RETURN
  60.  
  61. GotFunction:
  62.   GetToken  'token$=function's name
  63.  
  64.   REM **** prepend conflicting tokens with 'x' ****
  65.   k$ = token$
  66.   FOR k = 0 TO cnt-1
  67.      IF k$ = con$(k) THEN token$ = "x" + token$ 
  68.   NEXT   
  69.   REM **********************************************
  70.  
  71.   funcOffset=offset
  72.   offset=offset-6
  73.   parms$=""
  74.   SkipTill "(": IF char$="" THEN BadFileFormat
  75.   SkipTill ")": IF char$="" THEN BadFileFormat
  76.   GetChar
  77.   IF char$<>"" THEN
  78.     SkipTill "(": IF char$="" THEN BadFileFormat
  79.     WHILE char$ <> ")"
  80.       GetChar 'skip ( or , or /
  81.       IF char$<>")" THEN
  82.         GOSUB GetRegister
  83.         IF register=0 THEN BadFileFormat
  84.         IF register=-1 THEN
  85.           PRINT "Warning: Function ";token$;" not included because it"
  86.           PRINT " needs a parameter passed in a register BASIC cannot"
  87.           PRINT " conform to."
  88.           PRINT
  89.           RETURN
  90.         END IF
  91.         parms$ = parms$+CHR$(register)
  92.          'tells BASIC which register to put this parm into
  93.       END IF
  94.     WEND
  95.   END IF
  96.   AddEntry token$,funcOffset
  97.   PRINT #2,parms$;   'tells BASIC what registers to pass parms in
  98.   PRINT #2,CHR$(0);  'marks end of function entry
  99.   RETURN
  100.  
  101. BadFileFormat:
  102.   PRINT "Error: ";fdFilename$;" has a format error"
  103.   PRINT "In line:";lineNum;":";buf$
  104.   PRINT "In column:";column
  105.   CLOSE
  106.   STOP
  107.   
  108.  
  109. 'map {d0,d1,d2,d3,d4,d5,d6,d7,a0,a1,a2,a3,a4} to {1,..,13}
  110. GetRegister:
  111.   uchar$=UCASE$(char$)
  112.   IF uchar$="D" THEN
  113.     register=1
  114.   ELSEIF uchar$="A" THEN
  115.     register = 9
  116.   ELSE
  117.     register=0  'error
  118.     RETURN
  119.   END IF
  120.   GetChar  'skip a or d
  121.   i=ASC(char$)-48
  122.   IF i<0 OR i>7 THEN register=0: RETURN  'error
  123.   GetChar  'skip digit
  124.   register=register+i
  125.   IF register>13 THEN register=-1  'error
  126.   RETURN
  127.  
  128. SUB AddEntry(nam$, liboffset%) STATIC
  129.   highByte = PEEK(VARPTR(liboffset%))
  130.   lowByte = PEEK(VARPTR(liboffset%)+1)
  131.   PRINT #2,nam$; CHR$(0); CHR$(highByte); CHR$(lowByte);
  132.   END SUB
  133.  
  134. SUB GetLine STATIC
  135.   SHARED buf$,column,lineNum
  136.   LINE INPUT #1,buf$
  137.   column = 0
  138.   GetChar
  139.   lineNum = lineNum+1
  140.   END SUB
  141.  
  142. SUB GetNum STATIC
  143.   SHARED num,token$
  144.   GetToken
  145.   num = VAL(token$)
  146.   END SUB
  147.  
  148. SUB GetToken STATIC
  149.   SHARED buf$,char$,token$
  150.   SkipWhiteSpace
  151.   token$=""
  152.   uchar$=UCASE$(char$)
  153.   WHILE ((uchar$>="A") AND (uchar$<="Z")) OR ((uchar$>="0") AND (uchar$<="9")) OR (uchar$="-")
  154.     token$=token$+char$
  155.     GetChar
  156.     uchar$ = UCASE$(char$)
  157.   WEND
  158.   END SUB
  159.  
  160. SUB SkipTill(stopChar$) STATIC
  161.   SHARED char$
  162.   WHILE (char$ <> stopChar$) AND (char$ <> "")
  163.     GetChar
  164.   WEND
  165.   END SUB
  166.  
  167. SUB SkipWhiteSpace STATIC
  168.   SHARED char$
  169.   WHILE (char$=" ") OR (char$=CHR$(9))
  170.     GetChar
  171.   WEND
  172.   END SUB
  173.  
  174. SUB GetChar STATIC
  175.   SHARED column,char$,buf$
  176.   column = column + 1
  177.   char$ = MID$(buf$,column,1)
  178.   END SUB
  179.        
  180. REM **** conficting token count and tokens ****                
  181. DATA 11                
  182. DATA abs, Close, Exit, Input, Open, Output
  183. DATA Read, tan, Translate, Wait, Write
  184.